// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Pan.java

package org.achartengine.tools;

import java.util.*;
import org.achartengine.chart.*;
import org.achartengine.renderer.XYMultipleSeriesRenderer;

// Referenced classes of package org.achartengine.tools:
//			AbstractTool, PanListener

public class Pan extends AbstractTool
{

	private List mPanListeners;

	public Pan(AbstractChart abstractchart)
	{
		super(abstractchart);
		mPanListeners = new ArrayList();
	}

	public void apply(float f, float f1, float f2, float f3)
	{
		if (mChart instanceof XYChart)
		{
			int i = mRenderer.getScalesCount();
			double ad[] = mRenderer.getPanLimits();
			boolean flag = ad != null && ad.length == 4;
			XYChart xychart = (XYChart)mChart;
			for (int j = 0; j < i; j++)
			{
				double ad1[] = getRange(j);
				double ad2[] = xychart.getCalcRange(j);
				if (ad1[0] == ad1[1] && ad2[0] == ad2[1] || ad1[2] == ad1[3] && ad2[2] == ad2[3])
					return;
				checkRange(ad1, j);
				double ad3[] = xychart.toRealPoint(f, f1, j);
				double ad4[] = xychart.toRealPoint(f2, f3, j);
				double d = ad3[0] - ad4[0];
				double d1 = ad3[1] - ad4[1];
				if (mRenderer.isPanXEnabled())
					if (flag)
					{
						boolean flag1 = ad[0] <= ad1[0] + d;
						boolean flag3 = ad[1] >= ad1[1] + d;
						if (flag1 && flag3)
							setXRange(ad1[0] + d, ad1[1] + d, j);
					} else
					{
						setXRange(ad1[0] + d, ad1[1] + d, j);
					}
				if (mRenderer.isPanYEnabled())
					if (flag)
					{
						boolean flag2 = ad[2] <= ad1[2] + d1;
						boolean flag4 = ad[3] < ad1[3] + d1;
						if (flag2 && !flag4)
							setYRange(ad1[2] + d1, ad1[3] + d1, j);
					} else
					{
						setYRange(ad1[2] + d1, ad1[3] + d1, j);
					}
			}

		} else
		{
			RoundChart roundchart = (RoundChart)mChart;
			roundchart.setCenterX(roundchart.getCenterX() + (int)(f2 - f));
			roundchart.setCenterY(roundchart.getCenterY() + (int)(f3 - f1));
		}
		notifyPanListeners();
	}

	private synchronized void notifyPanListeners()
	{
		PanListener panlistener;
		for (Iterator iterator = mPanListeners.iterator(); iterator.hasNext(); panlistener.panApplied())
			panlistener = (PanListener)iterator.next();

	}

	public synchronized void addPanListener(PanListener panlistener)
	{
		mPanListeners.add(panlistener);
	}

	public synchronized void removePanListener(PanListener panlistener)
	{
		mPanListeners.add(panlistener);
	}
}
